#!/bin/bash

echo "#### start compile"

rm -rf /usr/local/out_igh
mkdir -p /usr/local/out_igh/

make clean ; make distclean
chmod +x bootstrap ; ./bootstrap
export PATH="/home/zqj/environment/gcc_rk3588/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/:$PATH"
export CC=aarch64-none-linux-gnu-gcc
export CXX=aarch64-none-linux-gnu-g++
export AR=aarch64-none-linux-gnu-ar
export LD=aarch64-none-linux-gnu-ld
export RANLIB=aarch64-none-linux-gnu-ranlib
export STRIP=aarch64-none-linux-gnu-strip

./configure \
    --prefix=/usr/local/out_igh/ \
    --with-linux-dir=/home/zqj/1git_code/kernel-5.10.160-rt \
    --enable-8139too=no \
    --host=aarch64-none-linux-gnu \
    --target=aarch64-none-linux-gnu \
    --disable-hrtimer \
    --enable-kernel \
    --disable-eoe \
    --enable-generic=yes
    # --disable-generic
    # --enable-sunxi-gmac=yes \

# 脚本内部禁止使用 sudo, 会重置环境变量 
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- -j8
make install -j8
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- modules -j8


mkdir -p /usr/local/out_igh/driver
cp -rf ./devices/*.ko /usr/local/out_igh/driver
cp -rf ./master/*.ko /usr/local/out_igh/driver
cp -rf ./examples/mini/*.ko /usr/local/out_igh/driver

cp -rf install_igh*.sh /usr/local/out_igh/
chmod +x /usr/local/out_igh/install_igh*.sh


sudo rm /usr/local/out_igh.zip
cd /usr/local
zip -r /usr/local/out_igh.zip ./out_igh/*
cd -

cp -rf /usr/local/out_igh.zip /mnt/hgfs/0VMware_share/

# cd ./my_application
# sudo ./1build_app.sh
# cd -
